// JavaScript Document
/*
修改画布尺寸
这么没有用到文档加载完毕的方法，用了引入js的defer属性，自动在文档加载完毕之后才执行
*/

(function(){
		  
	//点击修改尺寸按钮
	$('#resizeBtn').bind('click',function(e){
		e = e||window.event;
		if($("#resizePanel").is(":hidden")){
			var top =  e.clientY;
			var left =e.clientX;
			$("#resizePanel")[0].style.left = "550px"; 
			$("#resizePanel")[0].style.top = top-20   + "px";
			$("#resize-w").val(canvas.width);
			$("#resize-h").val(canvas.height);
			$('#quickResize').val(100);
			$("#resizePanel").fadeIn();
		}else{
			$("#resizePanel").fadeOut();
		}  		  
	});
	
	//应用
	$('#doResize').bind('click',function(e){
		//$("#canvasContainer > canvas").attr({ width: $("#resize-w").val()||canvas.width, height: $("#resize-h").val()||canvas.height});
		setCanvasSize(($("#resize-w").val()||canvas.width),($("#resize-h").val()||canvas.height));
		closeResizeWin();
	});
	
	//快速调节silider
	$('#quickResize').bind('change',function(e){
		var val = e.currentTarget.value;
		var cw = canvas.width,ch=canvas.height;
		$("#resize-w").val(Math.round(cw*val/100));
		$("#resize-h").val(Math.round(ch*val/100));
		$('#quickResizeTxt').html(val+"%");
	});
	
	//是否锁定宽高
	$('#isLock').bind('click',function(e){
			var isLock = e.currentTarget.checked;
			$("#resize-w").attr('readOnly',isLock);
			$("#resize-h").attr('readOnly',isLock);
			$('#quickResize').attr('readOnly',!isLock);
			var isLockImage = isLock ? "images/lock.png" : "images/unlock.png";
			$("#lockImg").attr("src",isLockImage);;

	});
	
	//点击关闭按钮
	$('#resizeCloseIcon').bind('click',closeResizeWin);
	$('#resizeCloseBtn').bind('click',closeResizeWin);
	
	//关闭窗口
	function closeResizeWin(){
		$("#resizePanel").fadeOut(); 
		
	}
})();